package com.example.spring_mvc.web;

import com.example.spring_mvc.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class UserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //ApplicationContext applicationContext = new ClassPathXmlApplicationContext("application.xml");
        ServletContext servletContext = req.getServletContext();
        ApplicationContext application = (ApplicationContext) servletContext.getAttribute("application");
        UserService userService = application.getBean(UserService.class);
        userService.save();
    }
}
